var temp_market_list = {
  自选: [
    {
      Coin_name: "LTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.912",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,569.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "LTC",
      Coin_local: "BNB",
      Coin_volume: "174,597.34",
      Coin_USD: "7.612",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,519.34",
      Coin_USD: "7.312",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "LTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    }
  ],
  BNB: [
    {
      Coin_name: "BNB",
      Coin_local: "BNB",
      Coin_volume: "174,559.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,597.34",
      Coin_USD: "7.832",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,539.34",
      Coin_USD: "7.112",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,539.34",
      Coin_USD: "7.112",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    }
  ],
  BTC: [
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,499.34",
      Coin_USD: "7.212",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,399.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,539.34",
      Coin_USD: "7.112",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,539.34",
      Coin_USD: "7.112",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,539.34",
      Coin_USD: "7.112",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    }
  ],
  ETH: [
    {
      Coin_name: "ETH",
      Coin_local: "BNB",
      Coin_volume: "174,559.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "ETH",
      Coin_local: "BNB",
      Coin_volume: "174,299.34",
      Coin_USD: "7.312",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.112",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,539.34",
      Coin_USD: "7.112",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    }
  ],
  USDT: [
    {
      Coin_name: "LTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "USDT",
      Coin_local: "BNB",
      Coin_volume: "174,499.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,589.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,199.34",
      Coin_USD: "7.312",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,539.34",
      Coin_USD: "7.112",
      Coin_CNY: "434.91",
      Coin_rise_fall: "-5.71"
    },
    {
      Coin_name: "BTC",
      Coin_local: "BNB",
      Coin_volume: "174,599.34",
      Coin_USD: "7.812",
      Coin_CNY: "434.91",
      Coin_rise_fall: "5.71"
    }
  ]
};

var star_dict = {
  btc2bitcny: 0,
  eth2bitcny: 1,
  ant2bitcny: 0,
  ltc2bitcny: 1,
  bch2bitcny: 0
};

var vue;
function vue_init(market_pairs, market_list) {
  vue = new Vue({
    el: "#market-app",
    data: {
      mdata: market_pairs,
      select_market: "BITCNY", //默认分类
      all_data: market_list,
      now_data_list: {},
      sort: "v", //排序方法 n按名称排序 v按成交量排序 p按价格排序 h按24小时涨跌排序
      order: "asc", //asc顺序排序 desc倒序排序
      chg: true
    },
    delimiters: ["{!", "!}"],
    methods: {
      init: function() {
        this.change_data_list(this.select_market);
      },
      sel_market: function(m_name) {
        this.select_market = m_name;
        this.change_data_list(m_name);
      },
      change_data_list: function(m_name) {
        // console.log(m_name);
        this.now_data_list = this.all_data[m_name];
        /* 添加一个收藏列表的状态码，这个是假数据 */
        for (var i = 0; i < this.now_data_list.length; i++) {
          switch (this.now_data_list[i].coin_type) {
            case "btc":
            this.now_data_list[i].is_collect = star_dict.btc2bitcny;
              break;
            case "eth":
                this.now_data_list[i].is_collect = star_dict.eth2bitcny;
              break;
            case "ant":
                this.now_data_list[i].is_collect = star_dict.ant2bitcny;
              break;
            case "ltc":
                this.now_data_list[i].is_collect = star_dict.ltc2bitcny;
              break;
            case "bch":
                this.now_data_list[i].is_collect = star_dict.bch2bitcny;
              break;
          }
        }
        // console.log(this.now_data_list);
      },
      change_sort: function(sort) {
        if (this.sort == sort) {
          if (this.order == "asc") {
            this.order = "desc";
          } else {
            this.order = "asc";
          }
        } else {
          this.order = "asc";
        }
        this.sort = sort;

        //更新排序 待定
      },
      to_coin_detail: function(coin, e) {
        //alert(coin);
        //e.preventDefault();
      },
      on_click_url: function(item) {
        //alert("333");
        window.location.href =
          "/m/trade#/trade?symbol=" + item.coin_type + "2" + item.use_coin_type;
      },

      /* 显示交易的列表 */
      show_search: function() {
        layer.open({
          className: "depositlist",
          type: 1,
          content: $("#testbox").html(),
          anim: "up",
          style:
            "background: #12161C;color: #f3f3f3;position:fixed; left:0; top:0; width:100%; height:100%; border: none; -webkit-animation-duration: .5s; animation-duration: .5s;"
        });
      },

      /* 点击收藏 */
      to_collect: function(index) {
        // console.log(123);
        // console.log(index);
        // console.log($(`#mun_${index}`));
        /* 添加一个询问弹窗 */
        if(this.now_data_list[index].is_collect){
            var content = "你确定要删除这个到收藏吗？";
        }else{
            var content = "你确定要添加这个到收藏吗？";
        }
        
        var style = 'border:none; background-color:#fff; color:#333; border-radius:0px'
        layer.open({
            content: content,
            btn: ['确定', '取消'],
            style: style,
            yes: (i) => {
                this.now_data_list[index].is_collect = !this.now_data_list[index].is_collect;
                // console.log(this.now_data_list[index].is_collect);
                $(`#mun_${index}`).toggleClass("collect");
                layer.close(i);
            }
        });
      }
    }
  });
  vue.init();
}
